//用户管理模块的接口
import request from '@/utils/request'

import type {
  UserResponseData,
  userFormData,
  User,
  AllRoleResponseData,
  SetRoleData,
} from './type'

//枚举地址
enum API {
  //获取全部已有用户账号信息
  ALLUSER_URL = '/user/findAllUserInfo/',
  //添加一个新的用户账号
  ADDUSER_URL = '/user/addUser',
  //更新已有的用户账号
  UPDATEUSER_URL = '/user/updateUser',
  //删除某一个账号
  DELETEUSER_URL = '/user/deleteUser/',
  //批量删除的接口
  DELETEALLUSER_URL = '/user/deleteUsers',
  //获取全部职位,当前账号拥有的职位接口
  ALLROLEURL = '/user/findAllRoleAndUserRole/',
  //给已有的用户分配角色接口
  SETROLE_URL = '/user/addUserRole',
}

//获取用户账号信息的接口
export const reqFindAllUserInfo = (
  page: number,
  limit: number,
  userForm: userFormData,
) =>
  request.get<any, UserResponseData>(API.ALLUSER_URL + `${page}/${limit}`, {
    params: userForm,
  })

//添加用户与更新已有用户的接口
export const reqAddOrUpdateUser = (data: User) => {
  //携带参数有ID更新
  if (data.userId) {
    return request.put<any, any>(API.UPDATEUSER_URL, data)
  } else {
    return request.post<any, any>(API.ADDUSER_URL, data)
  }
}

//删除某一个账号的信息
export const reqRemoveUser = (userId: number) =>
  request.delete<any, any>(API.DELETEUSER_URL + `${userId}`)

//批量删除的接口
export const reqRemoveUsers = (idList: number[]) =>
  request.delete(API.DELETEALLUSER_URL, { data: idList })

//获取全部职位以及包含当前用户的已有的职位
export const reqFindAllRoleAndUserRole = (userId: number) =>
  request.get<any, AllRoleResponseData>(API.ALLROLEURL + `${userId}`)
//分配职位
export const reqSetUserRole = (data: SetRoleData) =>
  request.post<any, any>(API.SETROLE_URL, data)
